package org.lql.chaos.rocketmq.service.consumer;

import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;

/**
 * @author: liangqinglong
 * @date: 2025-08-17 18:10
 * @description:
 **/
@Slf4j
@Service
@RocketMQMessageListener(
		topic = "test-topic",
		consumerGroup = "ext-consumer-group"
)
public class ExtConsumer implements RocketMQListener<MessageExt> {

	@Override
	public void onMessage(MessageExt messageExt) {
		String body = new String(messageExt.getBody(), StandardCharsets.UTF_8);
		log.info("接收到消息ID={}, 重试次数={}, 内容={}",
				messageExt.getMsgId(),
				messageExt.getReconsumeTimes(),
				body);
	}
}
